package com.equdao.car_violation_inquiry.utils;

import com.equdao.car_violation_inquiry.enums.CarTypeEnum;
import com.equdao.car_violation_inquiry.pojo.BasicCarDO;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class  CsvUtils {

    public static ArrayList<BasicCarDO> getCsvInfo(String path,String oldFileName,String newFileName) {

        DataInputStream in = null;
        BufferedReader br = null;
        try {
            in = new DataInputStream(new FileInputStream(new File(path)));
            br = new BufferedReader(new InputStreamReader(in, "GBK"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }
        String line = "";
        String everyLine = "";
        ArrayList<BasicCarDO> basicCarDOS = new ArrayList<>();
        try {
            int i = 0;
            while ((line = br.readLine()) != null)  //读取到的内容给line变量
            {
                everyLine = line;
                System.out.println(everyLine);
                if (i>0){
                    everyLine = line;
                    System.out.println(everyLine);
                    String[] split = everyLine.split(",");
                    BasicCarDO basicCarDO = new BasicCarDO();

                    basicCarDO.setFileName(oldFileName);
                    basicCarDO.setCarType(CarTypeEnum.PARAM_ERROR.getCode()+"");

                    basicCarDO.setVehicleNo(split[0]);//添加
                    basicCarDO.setFrameNo(split[1]);
                    basicCarDO.setEngineNo(split[2]);

                    basicCarDO.setFlag(newFileName);
                    basicCarDO.setStatus("0");

                    basicCarDOS.add(basicCarDO);
                }else {
                    i++;
                }
            }
            System.out.println("csv表格中所有行数：" + basicCarDOS.size());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return basicCarDOS;
    }
}
